package com.goldcn.user.controller;

import com.goldcn.user.dto.CompanySelectDto;
import com.goldcn.user.dto.CompanySelectPurchaseDto;
import com.goldcn.user.dto.SettleTypeDto;
import com.goldcn.user.dto.StateDto;
import com.goldcn.user.model.CompanyBankaccount;
import com.goldcn.user.service.CompanyInfoService;
import com.goldcn.user.vo.CompanyInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by 1111 on 2016/11/14.
 */
@Api(value = "供应商(店铺)管理")
@RestController
@RequestMapping(value = "/company")
public class CompanyInfoController {
    @Autowired
    CompanyInfoService companyInfoService;

    @ApiOperation(value = "供应商详情查询（包括图片文件）")
    @RequestMapping(value = "/{companyID}",method = RequestMethod.GET)
    public Object selectcompanyInfoByID(@PathVariable Long companyID){
        return companyInfoService.selectcompanyInfoByID(companyID);
    }

    @ApiOperation(value = "供应商基本信息查询")
    @RequestMapping(value = "/base/{companyID}",method = RequestMethod.GET)
    public Object selectCompany(@PathVariable Long companyID){
        return companyInfoService.selectCompany(companyID);
    }

    @ApiOperation(value = "修改供应商信息||修改店铺信息")
    @RequestMapping(method = RequestMethod.PUT)
    public Object updateCompanyInfo(@RequestBody CompanyInfoVo companyInfoVo)throws Exception{
        return companyInfoService.updateCompanyInfo(companyInfoVo);
    }

    @ApiOperation(value = "银行账户添加OR修改（修改需要传id）")
    @RequestMapping(value = "/addOrUpdate",method = RequestMethod.POST)
    public Object addOrUpdateAccount(@RequestBody CompanyBankaccount companyBankaccount){
        return companyInfoService.addOrUpdateAccount(companyBankaccount);
    }

    @ApiOperation(value = "查询供应商银行账户")
    @RequestMapping(value = "/bankAccount/{companyID}",method = RequestMethod.GET)
    public Object selectAccountByCompanyID(@PathVariable Long companyID){
        return companyInfoService.selectAccountByCompanyID(companyID);
    }

    @ApiOperation(value = "按条件查询供应商列表信息")
    @RequestMapping(value = "/selectList/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public Object selectListByCondition(@PathVariable int pageNum,@PathVariable int pageSize,@RequestBody CompanySelectDto selectDto){
        return companyInfoService.selectListByCondition(pageNum,pageSize,selectDto);
    }

    @ApiOperation(value = "按条件查询供应商列表信息——下拉列表用")
    @RequestMapping(value = "/selectPullList",method = RequestMethod.POST)
    public Object selectPullList(@RequestBody CompanySelectDto selectDto){
        return companyInfoService.selectPullList(selectDto);
    }

    @ApiOperation(value = "供应商审核(uID传companyID的值)")
    @RequestMapping(value = "/isAudit",method = RequestMethod.POST)
    public Object updateIsAudit(@RequestBody StateDto stateDto){
        return companyInfoService.updateIsAudit(stateDto);
    }

    @ApiOperation(value = "供应商查询")
    @RequestMapping(value = "/simple/{companyID}",method = RequestMethod.GET)
    public Object simpleCompany(@PathVariable Long companyID){
        return companyInfoService.selectByPrimaryKey(companyID);
    }

    @ApiOperation(value = "开启实时金价开关（0：关闭1：开启）")
    @RequestMapping(value = "/isGold",method = RequestMethod.POST)
    public Object updateIsGold(@RequestBody StateDto stateDto){
        return companyInfoService.updateIsGold(stateDto);
    }

    @ApiOperation(value = "中收结算方式（0.不结算,1.t+7,2月结）")
    @RequestMapping(value = "/settleType",method = RequestMethod.POST)
    public Object updateSettleType(@RequestBody SettleTypeDto settleTypeDto){
        return companyInfoService.updateSettleType(settleTypeDto);
    }

    @ApiOperation(value = "获取有中收结算方式的供应商")
    @RequestMapping(value = "/listBySettleType",method = RequestMethod.GET)
    public Object hasSettleType(){
        return companyInfoService.hasSettleType();
    }

    @ApiOperation(value = "按条件查询采购商列表信息")
    @RequestMapping(value = "/selectPurchaseList/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public Object selectPurchaseList(@PathVariable int pageNum, @PathVariable int pageSize, @RequestBody CompanySelectPurchaseDto selectDto){
        return companyInfoService.selectPurchaseListByCondition(pageNum,pageSize,selectDto);
    }

    @ApiOperation(value = "获取有中收结算方式的供应商")
    @RequestMapping(value = "/count/{groupID}",method = RequestMethod.GET)
    public Object countByGroupID(@PathVariable Long groupID){
        return companyInfoService.countByGroupID(groupID);
    }

    @ApiOperation(value = "获取二维码图片")
    @RequestMapping(value = "/qrcode/{content}",method = RequestMethod.GET)
    public void qrcode(@PathVariable String content, HttpServletResponse response){
        companyInfoService.qrcode(content,response);
    }



    @ApiOperation(value = "按条件查询分销商店铺列表信息")
    @RequestMapping(value = "/selectShopList/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public Object shopList(@PathVariable int pageNum, @PathVariable int pageSize, @RequestBody CompanySelectPurchaseDto selectDto){
        return companyInfoService.selectShopListByCondition(pageNum,pageSize,selectDto);
    }

}
